<?php


namespace App\Http\Controllers;


use App\Model\Cms;
use App\Model\ContactUs;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use function GuzzleHttp\Promise\all;

class ArticleController extends Controller
{

    public function info($info, Request $request)
    {
        $article = Cms::where('category', $info)->first();

        if (empty($article)) {
            abort(404);
        }
        $success = false;

        if ($request->isMethod('post')) {
            $validator = Validator::make($request->all(), [
                'name' => 'required|string',
                'email' => 'required|email',
                'phone' => 'required',
                'message' => 'required|string'
            ])->validate();

            $model = ContactUs::create([
                'name' => $validator['name'],
                'email' => $validator['email'],
                'mobile' => $validator['phone'],
                'message' => $validator['message']
            ]);
            $success = true;
        }

        return view('home.article', ['article' => $article, 'success' => $success]);
    }


}
